package ljl.alg.hot100;

public class _121_max_profit_easy {
    
    // 倒是也没问题，不过还可以更好点
    public int maxProfit2(int[] prices) {
        int min = prices[0], max = 0;
        for (int i = 1; i < prices.length; i++) {
            min = Math.min(min, prices[i]);
            max = Math.max(max, prices[i] - min);
        }
        return max;
    }
    
    // 这个明显更好了点
    public int maxProfit(int[] prices) {
        int min = prices[0], max = 0;
        for (int i = 1; i < prices.length; i++) {
            if (prices[i] < min) {
                min = prices[i];
            } else if (prices[i] - min > max) {
                max = prices[i] - min;
            }
        }
        return max;
    }
}
